import sys
from PyQt5.QtWidgets import (
    QApplication, QWidget, QVBoxLayout, QPushButton, QHBoxLayout, QStackedWidget
)
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QMessageBox, QFrame, QSplitter
from jsonFormat.timestamp_converter import TimestampConverter
from jsonFormat.format_json_qt5 import JSONFormatterApp


class MainPage(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
        # 设置窗口大小，这里设置宽度为 1200，高度为 800
        self.resize(2000, 1200)

    def initUI(self):
        main_layout = QHBoxLayout()

        # 左侧菜单栏
        menu_layout = QVBoxLayout()
        # JSON 转换按钮
        json_converter_btn = QPushButton("JSON 转换")
        json_converter_btn.clicked.connect(self.go_to_json_converter)
        menu_layout.addWidget(json_converter_btn)
        # 时间转换按钮
        timestamp_converter_btn = QPushButton("时间转换")
        timestamp_converter_btn.clicked.connect(self.go_to_timestamp_converter)
        menu_layout.addWidget(timestamp_converter_btn)
        # 让按钮顶部对齐
        menu_layout.addStretch(1)
        menu_widget = QWidget()
        menu_widget.setLayout(menu_layout)
        main_layout.addWidget(menu_widget, 1)  # 左侧占 20%


        # 右侧功能显示区域
        self.stacked_widget = QStackedWidget()
        self.timestamp_converter = TimestampConverter()
        self.json_converter = JSONFormatterApp()
        self.stacked_widget.addWidget(self.json_converter)
        self.stacked_widget.addWidget(self.timestamp_converter)
        main_layout.addWidget(self.stacked_widget, 9)  # 右侧占 80%

        self.setLayout(main_layout)

    def go_to_timestamp_converter(self):
        self.stacked_widget.setCurrentIndex(1)

    def go_to_json_converter(self):
        self.stacked_widget.setCurrentIndex(0)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_page = MainPage()
    main_page.show()
    sys.exit(app.exec_())